﻿/**
* @file unknow_banzidong.c
* @brief this is a brief description
* @details this is the detail description.
* @author fulong 
* @data 2014/12/24
* @version 1.0
* @par Copyright (c):
* @par First build
*     version: fulong 
*     data: 2014/12/24
*/
//XT06004_V1.0.PCB
//改动于07.04.25
//加要时间设置，当X007 = 1时为按键有效
//欧款半自动颗粒机
//INPUT IO
//X000    开始 
//X001    
//X002    脚踏开关
//X003    装料信号(打紧料主轴的最高点)
//X004    送料气缸前
//X005    送料气缸后
//X006    
//X007　　

//OUTPUT IO
//Y000    	冲压气缸
//Y001　　	夹料气缸    
//Y002		护料气缸    送料气缸	

//P00		延时松夹料时间退回
//P01		延时装料时间
//P02		延时夹料夹紧时间送出

#include "unknow_banzidong.h"
#include "../../../../dev/input.h"
#include "../../action.h"
#include "../../../../lib/delay.h"

#ifdef __XT14042__
extern input_status_process status_process;
static uint8  cRun_Step = 0, bRunning = 0, direct_go = 0;

static void unknow_banzidong_checkstart(void) {
//		启动	 停止		  　
    if (X00_UP && (X02) && (!X03) && (X04) && (!X05) && (!X01) && (!bRunning)) {   //自动启动
        bRunning = 1;       //运行标志位
        cRun_Step = 1;
    }
    if (X01_UP) {
        bRunning = 0;
        Y00 = 0;
        Y01 = 1;
        Y02 = 1;
    }
    if (X01_DW) {
        bRunning = 1;
        cRun_Step = 7;
        direct_go = 1;
    }
}
static void unknow_banzidong_action(void) {
    if (bRunning) {
        switch (cRun_Step) {
            case 1:
                Y00 = 1;
                cRun_Step++;
                break;
            case 2:
                if (X03) {
                    cRun_Step++;
                    apply4delay(ACTION_DELAY_FLAG, 10);
                }
                break;
            case 3:
                if (get_delay_flag(ACTION_DELAY_FLAG)) {
                    Y00 = 0;
                    cRun_Step++;
                }
                break;
            case 4:
                if (X02) {
                    Y01 = 1;
                    apply4delay(ACTION_DELAY_FLAG, 50);
                    cRun_Step++;
                }
                break;
            case 5:
                if (get_delay_flag(ACTION_DELAY_FLAG)) {
                    Y02 = 1;
                    cRun_Step++;
                }
                break;
            case 6:
                if (X05) {
                    apply4delay(ACTION_DELAY_FLAG, 100);
                    cRun_Step++;
                }
                break;
            case 7:
                if (get_delay_flag(ACTION_DELAY_FLAG) || direct_go != 0) {
                    Y01 = 0;
                    apply4delay(ACTION_DELAY_FLAG, 30);
                    cRun_Step++;
                }
                break;
            case 8:
                if (get_delay_flag(ACTION_DELAY_FLAG)) {
                    Y02 = 0;
                    cRun_Step++;
                }
                break;
            case 9:
                if (X04) {
                    cRun_Step++;
                    cRun_Step = 0;
                    bRunning = 0;
                    direct_go = 0;
                }
                break;
        }
    }
}
void unknow_banzidong(void) {
    unknow_banzidong_checkstart();
    unknow_banzidong_action();
}
#endif

